package com.iplay.实战java高并发程序设计.chapter2;

/**
 * @author dangwu
 * @since 2021/4/30 5:06 下午
 */
public class DaemonDemo {

    public static class DaemonT extends Thread{
        @Override
        public void run() {
            while (true){
                System.out.println("i am alive");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread t = new DaemonT();
        //如果设置守护线程失败，那么该线程也能正常执行，而且它是用户线程的身份。比如线程开始后再设置守护线程，就会报错。
        t.setDaemon(true);
        t.start();
        Thread.sleep(3000);
        System.out.println("main over");

    }
}
